﻿using System;
using Validate.Net.Core;

namespace Validate.Net.Internals.Regulars
{
    /// <summary>
    /// 自定义正则验证
    /// </summary>
    public sealed class CustomRegexAttribute : ValidateRegexBaseAttribute
    {
        /// <summary>
        /// 自定义正则验证
        /// </summary>
        /// <param name="pattern">自定义正则表达式</param>
        /// <param name="internalPrompts">内联提示语。优先级最高
        /// <list type="bullet">
        /// <item>提示语只描述校验失败的原因，而不应该包含其他内容。（ 例如 : 不能是默认值、必须填写 等等类似的语句 )</item>
        /// <item>内联提示语将覆盖所有其他设置</item>
        /// <item>提示语优先级: <see cref="ValidateBaseAttribute.InternalPrompts"/> > <see cref="CustomPrompts.Set{T}(string)"/> > <see cref="ValidateBaseAttribute.Prompts"/></item>
        /// </list>
        /// </param>
        public CustomRegexAttribute(string pattern, string internalPrompts = null) : base(internalPrompts)
        {
            if (string.IsNullOrWhiteSpace(pattern))
            { throw new ArgumentException($"“{nameof(pattern)}”不能为 null 或空白。", nameof(pattern)); }

            Pattern = pattern;
        }

        public override string Prompts => Properties.Resources.CustomRegexPrompts;
    }
}
